package com.dd.admin.business.server.controller;

import cn.hutool.core.bean.BeanUtil;
import com.dd.admin.common.security.SecurityUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.dd.admin.common.model.UpdateGroup;
import com.dd.admin.common.model.result.ResultBean;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotBlank;
import com.dd.admin.business.server.entity.Server;
import com.dd.admin.business.server.domain.ServerVo;
import com.dd.admin.business.server.domain.ServerDto;
import com.dd.admin.business.server.service.ServerService;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 服务人员表 前端控制器
 * </p>
 *
 * @author 727869402@qq.com
 * @since 2024-11-28
 */
@Api(tags = "服务人员表")
@RestController
public class ServerController {

    @Autowired
    ServerService serverService;

    @ApiOperation(value = "服务人员表-分页列表")
    @ApiOperationSupport(order = 1)
    @GetMapping("/admin/server/page")
    public ResultBean<IPage<ServerVo>> page(ServerDto serverDto) {
        serverDto.setShopId(SecurityUtil.getLoginUser().getDeptId());
        IPage<ServerVo> pageInfo = serverService.selectServerPage(serverDto);
        return ResultBean.success(pageInfo);
    }

    @ApiOperation(value = "服务人员表-列表")
    @ApiOperationSupport(order = 2)
    @GetMapping("/admin/server/list")
    public ResultBean<List<ServerVo>> list(ServerDto serverDto) {
        List<ServerVo> list = serverService.selectServerList(serverDto);
        return ResultBean.success(list);
    }

    @ApiOperation(value = "服务人员表-添加")
    @ApiOperationSupport(order = 3)
    @PostMapping("/admin/server/add")
    public ResultBean<Server> add(@RequestBody @Validated ServerDto serverDto) {
        Server server = BeanUtil.copyProperties(serverDto, Server.class);
        serverService.save(server);
        return ResultBean.success(server);
    }

    @ApiOperation(value = "服务人员表-查询")
    @ApiOperationSupport(order = 4)
    @GetMapping("/admin/server/{serverId}")
    public ResultBean<ServerVo> get(@PathVariable @NotBlank String serverId) {
        Server server = serverService.getById(serverId);
        ServerVo serverVo = BeanUtil.copyProperties(server,ServerVo.class);
        return ResultBean.success(serverVo);
    }

    @ApiOperation(value = "服务人员表-修改")
    @ApiOperationSupport(order = 5)
    @PostMapping("/admin/server/update")
    public ResultBean<Server> update(@RequestBody @Validated(UpdateGroup.class) ServerDto serverDto) {
        Server server = BeanUtil.copyProperties(serverDto, Server.class);
        serverService.updateById(server);
        return ResultBean.success(server);
    }

    @ApiOperation(value = "服务人员表-删除")
    @ApiOperationSupport(order = 6)
    @GetMapping("/admin/server/delete/{serverId}")
    public ResultBean<Server> delete(@PathVariable @NotBlank String serverId) {
        Boolean b = serverService.removeById(serverId);
        return ResultBean.success(b);
    }
}
